﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UpdateServers.Command;
using UpdateServers.Models;

namespace UpdaterClient
{
    /// <summary>
    /// 设置更新目录
    /// </summary>
    public partial class SetDirFile : Form
    {
        private FileConfigModels fileConfigModels;
        public SetDirFile()
        {
            InitializeComponent();

        }

        private void SetDirFile_Load(object sender, EventArgs e)
        {
            fileConfigModels = FileConfigHelper.GetFileConfig();
            if (fileConfigModels != null)
            {
                this.txt_SelectDir.Text = fileConfigModels.FolderRoot;
            }
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_DIrSave_Click(object sender, EventArgs e)
        {
            var dirroot = this.txt_SelectDir.Text.Trim();
            if (Directory.Exists(dirroot))
            {
                FileConfigHelper.SetFileConfig(new FileConfigModels { FolderRoot = dirroot });

                this.Close();
            }
            else
            {
                MessageBox.Show("目录路径不存在！", "提示");
            }
        }

        /// <summary>
        /// 选择文件夹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_Select_Click(object sender, EventArgs e)
        {
            var dirroot = this.txt_SelectDir.Text.Trim();

            this.folderBrowserDialog1.Description = "请选择文件夹";
            this.folderBrowserDialog1.ShowNewFolderButton = true;
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                this.txt_SelectDir.Text = folderBrowserDialog1.SelectedPath;
            }           

        }
    }
}
